package ru.spbau.lifeincube.math;

import javafx.geometry.Point3D;

public class Vector3D {
	private Point3D p;

	public Vector3D(Point3D direction) {
		this.p = direction;
	}

	public double length() {
		return length(p);
	}

	public double getX() {
		return p.getX();
	}

	public double getY() {
		return p.getY();
	}

	public double getZ() {
		return p.getZ();
	}

	private double length(Point3D p) {
		return Math.sqrt(p.getX() * p.getX() + p.getY() * p.getY() + p.getZ() * p.getZ());
	}

	public void normalize() {
		double len = length();
		if (len <= 1e-5) {
			p = new Point3D(0.0, 0.0, 1.0);
			return;
		}
		p = new Point3D(p.getX() / len, p.getY() / len, p.getZ() / len);
	}
}
